$(document).ready(function()
    {
        $.fill_list_pinjaman = function(data)
        {
            $("#LIST_PINJAMAN_BARU tbody").html("");
            var status = "";
            var color = "";
            if(data.data != null)
                for(var i = 0; i < data.data.length ; i++)
                {
                    var current = data.data[i];

                    $("#LIST_PINJAMAN_BARU tbody").append("<tr style='background-color: "+color+";'>\n\
                                                        <td>"+current.ID_ANGGOTA+"</td>\n\
                                                        <td>"+current.NAMA_ANGGOTA+"</td>\n\
                                                        <td>"+current.ID_PINJAMAN+"</td>\n\
                                                        <td>"+current.TGL_PINJAMAN+"</td>\n\
                                                        <td>"+current.URAIAN_USAHA+"</td>\n\
                                                        <td class='currency'>"+current.MARGIN+"</td>\n\
                                                        <td class='currency'>"+current.JUMLAH_PINJAMAN+"</td>\n\
                                                        </tr>");
                }
                $(".currency").formatCurrency();
        }

        $('#LIST_PINJAMAN_BARU tbody tr').live('click', function()
        {
            $.listPinjamanRowClicked(this);
        });

        $.listPinjamanRowClicked = function(data)
        {
            if($('td:first', data).html() != 'No matching records found')
            {
                window.location = base_url + "br-03/peminjaman/detail/" + $('td:eq(2)', data).html();
            }
        }

        $.data_ajax('br-03/peminjaman/data_pinjaman_baru/', null, $.fill_list_pinjaman);
    });